package com.liukai.user.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.liukai.novel_base.base.BaseActivity;
import com.liukai.novel_commons.db.DBHelper;
import com.liukai.novel_commons.db.UserInfoService;
import com.liukai.novel_commons.utils.Constans;
import com.liukai.novel_commons.utils.DBManager;
import com.liukai.novel_commons.utils.LogUtils;
import com.liukai.novel_commons.utils.MyInfoList;
import com.liukai.user.R;
import com.liukai.user.R2;
import com.liukai.user.adapter.MyInfoRecyclerAdapter;
import com.liukai.user.adapter.SettingRecyclerAdapter;

import butterknife.BindView;

public class SettingActivity extends BaseActivity {

    @BindView(R2.id.recyclerView)
    RecyclerView mRecyclerView;

    @BindView(R2.id.btn_back)
    TextView btnBack;

    private Context mContext;

//    private SettingRecyclerAdapter mSettingRecyclerAdapter;

    private MyInfoRecyclerAdapter mMyInfoRecyclerAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected void initData(Context context) {
        this.mContext = SettingActivity.this;
    }

    @Override
    protected void initView() {

        mMyInfoRecyclerAdapter = new MyInfoRecyclerAdapter(MyInfoList.getSettingList());
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        mRecyclerView.setLayoutManager(linearLayoutManager);
        mRecyclerView.setAdapter(mMyInfoRecyclerAdapter);

    }

    @Override
    protected void initListener() {

        mMyInfoRecyclerAdapter.setItemClick(new MyInfoRecyclerAdapter.ItemClick() {
            @Override
            public void onItemClickListener(String itemName) {
                // 点击退出登录
                if (itemName.equals(Constans.LOGOUT)) {
                    UserInfoService userInfoService = new UserInfoService(mContext);
                    int i = userInfoService.deleteUserInfoById(Constans.getUserInfo().getUserId());
                    LogUtils.e(getClass(),"deleteUserInfoById==========>" + i);
                    setResult(Constans.CODE_RESULT_SettingActivity);
                    finish();
                }
                Toast.makeText(SettingActivity.this, itemName, Toast.LENGTH_SHORT).show();
            }
        });

        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }
}
